import Vue from "vue";
import Vuex from "vuex";
import VuexPersistence from "vuex-persistedstate";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    example: {
      username: "zhangsan",
      age: 11,
    },
  },
  getters: {},
  mutations: {
    updateAge(state, payload) {
      state.example.age = payload;
    },
  },
  actions: {},
  modules: {},
  plugins: [
    // vuex plugin[]
    VuexPersistence({
      storage: window.sessionStorage,
      reducer: (state) => {
        return {
          example: state.example,
        };
      },
    }),
  ],
});
